1 package net.sourceforge.simplegamenet.chess; 2 3 public class ChessPawn extends ChessPiece { 4 5 public ChessPawn(int participantOwnerIndex, int x, int y) { 6 super(participantOwnerIndex, x, y); 7 } 8 9 public boolean isMoveAllowed(ChessPiece[] pieceGrid, 10 int destinationX, int destinationY) { 11 if (pieceGrid[destinationX * GRID_HEIGHT + destinationY] != null 12 && pieceGrid[destinationX * GRID_HEIGHT + destinationY] 13 .getParticipantsOwnerIndex() == participantOwnerIndex) { 14 return false; 15 } else if (pieceGrid[destinationX * GRID_HEIGHT + destinationY] != null 16 && Math.abs(x - destinationX) == 1 17 && y - destinationY == (participantOwnerIndex == 0 ? 1 : -1)) { 18 return true; 19 } else if (pieceGrid[destinationX * GRID_HEIGHT + destinationY] == null 20 && x == destinationX) { 21 if (y - destinationY == (participantOwnerIndex == 0 ? 1 : -1)) { 22 return true; 23 } else if (Math.abs(y - destinationY) == 2 24 && y == (participantOwnerIndex == 0 ? GRID_HEIGHT - 2 : 1) 25 && pieceGrid[destinationX * GRID_HEIGHT 26 + Math.min(y, destinationY) + 1] == null) { 27 return true; 28 } else { 29 return false; 30 } 31 } else { 32 return false; 33 } 34 } 35 36 public int getPieceType() { 37 return ChessPieceType.PAWN; 38 } 39 40 public int getPieceValue() { 41 return 1; 42 } 43 44 public boolean isReplaceChoiceNeeded(int destinationX, int destinationY) { 45 return y == (participantOwnerIndex == 0 ? 1 : GRID_HEIGHT - 2); 46 } 47 48 }